
var glMouseX
var glMouseY

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    //if (!sender.tab) return
    //if (!request.X) return;
    //if (!request.Y) return;

    //alert("request type: "+request.type);
    //alert("request text: "+request.text);

    if (!request.type || request.type != "translation") return;
    if (!request.text) return;


    $("#translate_text").html(request.text);
    $('#translate_dialog').dialog({
                "buttons" : [],
                "height" : "100",
                "width" : "400",
                "resizable": "false",
                "closeOnEscape" : true,
                "closeText": "Esc",
                "title" : request.title,
                "position" : [glMouseX, glMouseY]
            });
    $('#translate_dialog').dialog('open');
    setTimeout(function (){
        $('#translate_dialog').dialog('close');
        $('#translate_dialog').dialog( "destroy" );
    }, 5000)
});

$(document).ready(function (){
    $('body').append("<div id='translate_dialog' class='ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable'> \
                          <a ID='translate_text' style='font-size:12px'>Dialog content goes here.</a> \
                      </div>");

    $('#translate_dialog').hide();

});


$(document).mousemove(function(e){
      glMouseX = e.clientX;
      glMouseY = e.clientY;
   });

